<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>融资报价维护</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<style>
.error{
	color:red;
}
</style>
<body class="iframeBody">
	<div class="Wrapper">
		<div id="pageInTab" class="pageInTab">
			<form id="scm_bsc_info_form">
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">报价基础信息 </span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">报价名称</div>
						<div class="field">
								<input name="fncScmNm" id="fncScmNm" type="text"
									class="ui-textbox" value="${fncScmNm}" validate="{required:true,minlength:3}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">融资机构名称</div>
						<div class="field">
							<input name="fncInsNm" id="fncInsNm" type="text" class="ui-textbox" value="${fncInsNm}" disabled="disabled" >
							<input type="hidden" id="fncInsId" name="fncInsId" value="${fncInsId}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">授信名称</div>
						<div class="field">
							<input name="crId" id="crId" type="text" class="ui-textbox" value="${crId}" >
							<input type="hidden" id="crIdVal" name="crIdVal" value="${crId}">
							<input type="hidden" id="abs" name="abs" value="${abs}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">产品名称</div>
						<div class="field">
							<input name="pdId" id="pdId" type="text" class="ui-textbox" value="${pdId}">
							<input type="hidden" id="pdIdVal" name="pdIdVal" value="${pdId}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">计划封包日</div>
						<div class="field">
							<input name="stdt" id="stdt" type="text"
								class="ui-datepicker" value="${stdt}" validate="{required:true}">
								&nbsp;&nbsp; --- &nbsp;&nbsp;
							<input name="eddt" id="eddt" type="text"
								class="ui-datepicker" value="${eddt}" validate="{required:true}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">还款类别</div>
						<div class="field">
		                    <select name="rePyTpCd" id="rePyTpCd">
		                        <c:forEach items="${rePyTpCdLst}" var="rePyTpCd">
		                       		<c:choose>
			                       		<c:when test="${rePyTpCd.key == '1'}">
			                        		<option value="${rePyTpCd.key}" selected="selected">${rePyTpCd.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${rePyTpCd.key}">${rePyTpCd.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">业务类别</div>
						<div class="field">
		                    <select name="busType" id="busType">
		                        <c:forEach items="${busTypeLst}" var="busType">
		                       		<c:choose>
			                       		<c:when test="${busType.key == 'LB'}">
			                        		<option value="${busType.key}" selected="selected">${busType.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${busType.key}">${busType.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
				</div>
				
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">报价信息 </span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">融资基数</div>
						<div class="field">
		                    <select name="fncCrdnlt" id="fncCrdnlt">
			                    <option value="" selected="selected">请选择</option>
		                       	<c:forEach items="${fncCrdnltCdLst}" var="fncCrdnlt">
			                        		<option value="${fncCrdnlt.key}">${fncCrdnlt.value}</option>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">打折率(%)</div>
						<div class="field">
								<input name="dcnRate" id="dcnRate" type="text"
									class="ui-spinner" value="${dcnRate}" ligerui="{type:'float',max:100,min:0,decimalplace:4}">
						</div>
					</div>
					
					<div class="fieldBox col_50">
						<div class="label">融资期限(月)</div>
						<div class="field">
								<input name="fncTrm" id="fncTrm" type="text"
									class="ui-spinner" value="${fncTrm}" ligerui="{type:'int'}" validate="{digits:true}">
						</div>
					</div>
					<div class="fieldBox col_50">
					
						<div class="label">是否涉及境外</div>
						<div class="field">
							<select name="wthrSupAbr" id="wthrSupAbr" onchange="switchAbroadForm()">
		                       	<c:forEach items="${searchWthrKVList}" var="wthrSupAbr">
		                       		<c:choose>
			                       		<c:when test="${wthrSupAbr.key == '0'}">
			                        		<option value="${wthrSupAbr.key}" selected="selected">${wthrSupAbr.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${wthrSupAbr.key}">${wthrSupAbr.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					<div class="fieldBox col_50" id="s1">
						<div class="label">利率基准(%)</div>
						<div class="field">
							<input name="irtBs" id="irtBs" type="text"
									class="ui-spinner" value="${irtBs}" ligerui="{type:'float',max:100,min:0,decimalplace:4}">
						</div>
					</div>
					<div class="fieldBox col_50" id="s3">
						<div class="label">报价利率(%)
<!-- 							<span class="requiredSymbol">*</span> -->
						</div>
						<div class="field">
							<input name="scmIntrt" id="scmIntrt" type="text" validate="{required:true}" class="ui-spinner" value="${scmIntrt}" ligerui="{type:'float',max:100,min:0,decimalplace:4}" >
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">利率是否浮动</div>
						<div class="field">
							<select name="irtTpcd" id="irtTpcd" onchange="switchIrtForm()">
		                       	<c:forEach items="${searchWthrKVList}" var="irtTpcd">
		                       		<c:choose>
			                       		<c:when test="${irtTpcd.key == '0'}">
			                        		<option value="${irtTpcd.key}" selected="selected">${irtTpcd.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${irtTpcd.key}">${irtTpcd.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>			
					<div class="fieldBox col_50" title="intrtMtdcd">
						<div class="label">利率上浮方式</div>
						<div class="field">
		                    <select name="intrtMtdcd" id="intrtMtdcd">
		                       	<c:forEach items="${intrtMtdcdLst}" var="intrtMtdcd">
		                        	<c:choose>
			                       		<c:when test="${intrtMtdcd.key == '1'}">
			                        		<option value="${intrtMtdcd.key}" selected="selected">${intrtMtdcd.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${intrtMtdcd.key}">${intrtMtdcd.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					<div class="fieldBox col_50" id="s2">
						<div class="label">基准上浮比例(%)</div>
						<div class="field">
								<input name="bsFlotupRto" id="bsFlotupRto" type="text"
									class="ui-spinner" value="${bsFlotupRto}" ligerui="{type:'float',max:100,min:0,decimalplace:4}">
						</div>
					</div>					
					<div class="fieldBox col_50" title="prymMtd">
						<div class="label">调息方式</div>
						<div class="field">
		                    <select name="prymMtd" id="prymMtd">
		                       	<c:forEach items="${prymMtdLst}" var="prymMtd">
		                        	<c:choose>
			                       		<c:when test="${prymMtd.key == '1'}">
			                        		<option value="${prymMtd.key}" selected="selected">${prymMtd.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${prymMtd.key}">${prymMtd.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					
				</div>	
				<!-- 担保信息  start  -->
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">担保信息 </span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否担保</div>
						<div class="field">
		                    <select name="isGuarantee" id="isGuarantee">
		                    	<option value="">--请选择--</option>
		                    	<c:forEach items="${sysYNList}" var="sysyn">
		                    	  <option value="${sysyn.key }">${sysyn.value }</option>
		                    	</c:forEach>
		                   </select><font color="red">*</font>
		                </div>
		             </div>
		             <div class="fieldBox col_50">
						<div class="label">担保主体</div>
						<div class="field">
		                  	<input name="guaranteeBody" id="guaranteeBody" data-value="${bscinfo.guaranteeBody}"  placeholder="请选择"  ltype="combobox" >
		                </div>
		             </div>
		            <div class="fieldBox col_50">
						<div class="label">担保开始日</div>
						<div class="field">
		                    <input name="guaranteeStart" value="${bscinfo.guaranteeStart}" class="ui-datepicker" id="guaranteeStart" />
		                </div>
		             </div>
		            <div class="fieldBox col_50">
						<div class="label">担保到期日</div>
						<div class="field">
		                    <input name="guaranteeEnd" value="${bscinfo.guaranteeEnd}" class="ui-datepicker" id="guaranteeEnd"/>
		                </div>
		             </div>
		           <div class="fieldBox col_100">
						<div class="label">担保主体备注</div>
						<div class="field">
		                    <input name="guaranteeRemark" value="${bscinfo.guaranteeRemark}" id="guaranteeRemark" class="ui-textbox" />
		                </div>
		           </div>
				</div>
				<!-- 担保信息  end -->
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="caption">
						<span class="title">计费信息 </span>
						<div style="margin-left: auto;margin-right: 10px;width:200px;margin-top: -15px">
							<span id="scm_cost2_add_btn_id"
								class="sq-button sq-button-round" onclick="addNewCost1();">新增
							</span>
							<span id="scm_cost2_del_btn_id"
								class="sq-button sq-button-round" onclick="deleteRow1();" >删除选中行
							</span>
						</div>
					</div>
					<div class="fieldBox col_100">
							<div id="cost1" class="sq-grid">
							</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">方案XIRR(%)</div>
						<div class="field">
								<input name="irr" id="irr" type="text"
									class="ui-spinner" value="${irr}" ligerui="{type:'float',max:100,min:0,decimalplace:4}">
						</div>
					</div>
				</div>
				
				<div class="fieldset1 tabel_col tabel_col_s clearFix" id="abdform">
					<div class="caption">
						<span class="title">境外成本</span>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否存在汇率风险</div>
						<div class="field">
							<select name="exstExrtRsk" id="exstExrtRsk">
		                       	<c:forEach items="${searchWthrKVList}" var="exstExrtRsk">
		                       		<c:choose>
			                       		<c:when test="${exstExrtRsk.key == '0'}">
			                        		<option value="${exstExrtRsk.key}" selected="selected">${exstExrtRsk.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${exstExrtRsk.key}">${exstExrtRsk.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否存在利率风险</div>
						<div class="field">
							<select name="exstIntrtRsk" id="exstIntrtRsk">
		                       	<c:forEach items="${searchWthrKVList}" var="exstIntrtRsk">
		                       		<c:choose>
			                       		<c:when test="${exstIntrtRsk.key == '0'}">
			                        		<option value="${exstIntrtRsk.key}" selected="selected">${exstIntrtRsk.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${exstIntrtRsk.key}">${exstIntrtRsk.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">汇率风险承包方</div>
						<div class="field">
								<input name="exrtRskCntr" id="exrtRskCntr" type="text"
									class="ui-textbox" value="${exrtRskCntr}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">利率风险承包方</div>
						<div class="field">
								<input name="intrtRskCntr" id="intrtRskCntr" type="text"
									class="ui-textbox" value="${intrtRskCntr}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否承做汇率掉期</div>
						<div class="field">
							<select name="cmtExrtSwp" id="cmtExrtSwp">
		                       	<c:forEach items="${searchWthrKVList}" var="cmtExrtSwp">
		                       		<c:choose>
			                       		<c:when test="${cmtExrtSwp.key == '0'}">
			                        		<option value="${cmtExrtSwp.key}" selected="selected">${cmtExrtSwp.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${cmtExrtSwp.key}">${cmtExrtSwp.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">是否承做利率掉期</div>
						<div class="field">
							<select name="cmtIntrtSwp" id="cmtIntrtSwp">
		                       	<c:forEach items="${searchWthrKVList}" var="cmtIntrtSwp">
		                       		<c:choose>
			                       		<c:when test="${cmtIntrtSwp.key == '0'}">
			                        		<option value="${cmtIntrtSwp.key}" selected="selected">${cmtIntrtSwp.value}</option>
			                       		</c:when>
			                       		<c:otherwise>
			                        		<option value="${cmtIntrtSwp.key}">${cmtIntrtSwp.value}</option>
			                       		</c:otherwise>
		                       		</c:choose>
		                        </c:forEach>
		                    </select>
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">汇率掉期银行</div>
						<div class="field">
								<input name="exrtSwpBnk" id="exrtSwpBnk" type="text"
									class="ui-textbox" value="${exrtSwpBnk}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">利率掉期银行</div>
						<div class="field">
								<input name="intrtSwpBnk" id="intrtSwpBnk" type="text"
									class="ui-textbox" value="${intrtSwpBnk}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">汇率掉期费率(%)</div>
						<div class="field">
								<input name="exrtSwpFeert" id="exrtSwpFeert" type="text"
									class="ui-spinner" value="${exrtSwpFeert}" ligerui="{type:'float',max:100,min:0,decimalplace:4}">
						</div>
					</div>
					<div class="fieldBox col_50">
						<div class="label">利率掉期费率(%)</div>
						<div class="field">
								<input name="intrtSwpFeert" id="intrtSwpFeert" type="text"
									class="ui-spinner" value="${intrtSwpFeert}" ligerui="{type:'float',max:100,min:0,decimalplace:4}">
						</div>
					</div>					
				</div>	
				
				<div class="fieldset1 tabel_col tabel_col_s clearFix">
					<div class="fieldBox col_100">
						<div class="label">备注</div>
						<div class="field">
                			<textarea id="rmrk" style="width:100%" ></textarea>
						</div>
					</div>
				</div>			
			</form>
		</div>

		<div class="btnsBox">
			<span id="scm_bsc_info_add_btn_id" class="sq-button sq-button-round" >保存</span>
		</div>
	</div>

	<script type="text/javascript">
	    var combdata1,combdata2,griddata1,griddata2;
	  	//add 保证金使用方式  by gengchunlan 20180626
		var mrgnUseMtdJSON = [];
		<c:if test="${not empty mrgnUseMtdJSON}"> mrgnUseMtdJSON = ${mrgnUseMtdJSON}; </c:if>
	    // 验证值小数位数不能超过指定位数param  郭志强20170810
	    ///$.validator.addMethod("decimallen", function(value, element, param) {
	    //    var decimallen =eval("/^-?\\d+(\\.\\d{0," + param + "})?$/"); 
	    //    return this.optional(element) || (decimallen.test(value));
		//}, "小数位数不能超过{0}位");
	    //扩展一个 数字输入 的编辑器
        $.ligerDefaults.Grid.editors['numberbox'] = {
            create: function (container, editParm) {
                var column = editParm.column;
                var precision = column.editor.precision;
                var input = $("<input type='text' style='text-align:right' class='l-text' />");
                input.bind('keypress', function (e) {
                    var keyCode = window.event ? e.keyCode : e.which;
                    return keyCode >= 48 && keyCode <= 57 || keyCode == 46 || keyCode == 8;
                });
                input.bind('blur', function () {
                    var value = input.val();
                    input.val(parseFloat(value).toFixed(precision));
                });
                container.append(input);
                return input;
            },
            getValue: function (input, editParm) {
                return parseFloat(input.val());
            },
            setValue: function (input, value, editParm) {
            	if(typeof(value)=="undefined"){ 
            		console.log("undefined0");
            		value = 0;
            	}
                var column = editParm.column;
                var precision = column.editor.precision;
                input.val(parseFloat(value).toFixed(precision));
            },
            resize: function (input, width, height, editParm) {
                input.width(width ).height(height );
            }
        };

        //扩展 numberbox 类型的格式化函数
        $.ligerDefaults.Grid.formatters['numberbox'] = function (value, column) {
        	if(typeof(value)=="undefined"){ 
        		console.log("undefined1");
        		value = 0;
        	}
            var precision = column.editor.precision;
            return parseFloat(value).toFixed(precision);
        }; 

		$(function () {
			//REQ-15103  担保主体多选
			$("#guaranteeBody").ligerComboBox({ isShowCheckBox: true, isMultiSelect: true,
		     	   data: ${guaranteeBodyLst},
		            slide: false,
		            valueField: 'key', textField: 'value',
		            valueFieldID: 'guaranteeBody'
		      });
			f_initDatePicker();
			f_initCostData1();
			initCrLstForm();
			initPdList();
			hideIrtForm();
			hideAbroadForm();
        	$("#scm_bsc_info_form").ligerForm({
        		validate:true
            });
			saveScmBaseBtnEvent();
		});
		
	    function f_initCostData1()
	    { 
	    	griddata1 = $("#cost1").ligerGrid({
	                columns: [
		                { display: '费用名称', width: 150, name: 'costNm',type:'text',
		                    editor: { type: 'text' }
		                },
		                { display: '是否保证金', width: 100, name: 'mrgnIs',type:'text',
		                  editor: { type: 'select', 
									data: [
					                    { value: '否', key: '0' },
					                    { value: '是', key: '1' }
					                ],
									valueField: 'key', textField: 'value' },
	                    	render: function (item)
		                    {
		                        if (parseInt(item.mrgnIs) == 1) return '是';
		                        return '否';
		                    }
		                },
		                { display: '保证金到期处理方式', name: 'mrgnUseMtd', minWidth: 150 ,enabledSort:true,
		            	       validate:{required:true,minlength:1},
		            	editor: 
		            	 {
		                    type: 'select',
		                    data: mrgnUseMtdJSON,
		                    isMultiSelect: false,isShowCheckBox: false,
		                    valueField: 'key',
		                    textField: 'value'
				          },
			                valueField: 'mrgnUseMtd',
			                textField: 'mrgnUseMtdDes',
			                render: function (item) {
			                    return item.mrgnUseMtdDes;
			                }
		                },
		                { display: '费用比例(%)', width: 150, name: 'costPct',type:'text',
		                    editor: { type: 'text' }
		                },
		                { display: '费用金额', name: 'costAmt', width: 150, type: 'float', editor: { type: 'float'} }, 
	                { display: '是否计入首付款', name: 'costInTpCd',width: 150,
	                    editor: { type: 'select', 
									data: [
					                    { value: '首付款', key: '1' },
					                    { value: '分期付款', key: '2' },
					                    { value: '一次性付款', key: '3' }
					                ],
									valueField: 'key', textField: 'value' }, 
	                    render: function (item)
	                    {
	                        if (parseInt(item.costInTpCd) == 1) return '首付款';
	                        if (parseInt(item.costInTpCd) == 2) return '分期付款';
	                        if (parseInt(item.costInTpCd) == 3) return '一次性付款';
	                        return '分期付款';
	                    }
	                },
	                { display: '首付款是否坐扣', name: 'wthrDdct',width: 150,
	                    editor: { type: 'select', 
									data: [
					                    { value: '否', key: '0' },
					                    { value: '是', key: '1' },
					                    { value: '默认已付', key: '2' }
					                ],
									valueField: 'key', textField: 'value' },
	                    render: function (item)
	                    {
	                        if (parseInt(item.wthrDdct) == 1) return '是';
	                        if (parseInt(item.wthrDdct) == 2) return '默认已付';
	                        return '否';
	                    }
	                },
	                { display: '预计付款时间', name: 'prePayDate', type: 'date', format: 'yyyyMMdd', width: 100, editor: { type: 'date'} },
	                { display: '备注', name: 'rmrk', isSort: false,
	                    editor: { type: 'text' }
	                } 
	                ],
	                onSelectRow: function (rowdata, rowindex)
	                {
	                    $("#txtrowindex").val(rowindex);
	                },
	                enabledEdit: true, isScroll: false, checkbox:true,rownumbers:true,
	                onBeforeEdit: f_onBeforeEdit,
	                onBeforeSubmitEdit: f_onBeforeSubmitEdit,
// 	                onAfterEdit: f_onAfterEdit,
	                width: '100%'
	            }); 	    
	    }
	    //是否计入首付款为‘是’的时候，“是否坐扣”可编辑 默认0
	    function f_onBeforeEdit(e){
	        var manager = $("#cost1").ligerGetGridManager();
			var rowdata = manager.getRow(e.rowindex);
			var costin = rowdata.costInTpCd;
	        if (e.column.name == "wthrDdct"){
	        	if(costin == 1){
	        		return true;
	        	}else{
	        		return false;
	        	}
	        }
	    }
        function f_onBeforeSubmitEdit(e)
        { 
        	var manager = $("#cost1").ligerGetGridManager();
 		    var rowdata = manager.getRow(e.rowindex);
            var payval = e.value;
            if (e.column.name == "costPct")
            {       
             	if($.isNumeric(Number(payval))){
            		var len = payval.substring(payval.indexOf(".")+1,payval.length).length;
            		var intval = payval;
            		if(payval.indexOf(".")>0){
            			intval = payval.substring(0,payval.indexOf("."));
            		}
            		if(len>6 || intval>99){
	            		alert("数字不能大于100且小数位不能超过6位!");
	            		return false;
            		}
            		//费用比例（%）费用金额只能填一项
            		if(payval !=null && payval !="" && payval !="0" && rowdata.costAmt !=null && rowdata.costAmt !=""){
                 	    alert("计费信息中费用比例（%）和费用金额只能填写一项，请重新填写！");
         	           	return false;
                    }
            		return true;
            	}else{
            		alert("请输入数字!");
            		return false;
            	} 
             	
             	
            }
          //费用比例（%）费用金额只能填一项
            if (e.column.name == "costAmt")
            {          	
             	 if( payval !=null && payval !="" && rowdata.costPct !=null && rowdata.costPct !=""&& rowdata.costPct !="0"){
             	    alert("计费信息中费用比例（%）和费用金额只能填写一项，请重新填写！");
     	           	return false;
                }
            }
            return true; 
        }

//         //编辑后事件 
//        function f_onAfterEdit(e)
//        {
//     	 //费用比例（%）费用金额只能填一项
//            var manager = $("#cost1").ligerGetGridManager();
// 		   var rowdata = manager.getRow(e.rowindex);
// 		   var costPct = rowdata.costPct;
// 		   var costAmt = rowdata.costAmt;
//            if(costPct !=null && costPct !="" && costAmt !=null && costAmt !=""){
//         	    alert("计费信息中费用比例（%）和费用金额只能填写一项，请重新填写！");
// 	           	return false;
//            }
//        }
        function deleteRow1()
        { 
        	griddata1.deleteSelectedRow();
        }   
		
        function addNewCost1()
        {
        	griddata1.addRow({});
        } 
		
        function f_initDatePicker(){
        	$("#stdt").ligerDateEditor({ 
        		showTime: true, labelWidth: 100, labelAlign: 'left' ,format: 'yyyy-MM-dd',
        		onChangeDate : function(value){
        			$("#stdt").val(value);
        		}
        	});
        	$("#eddt").ligerDateEditor({ 
        		showTime: true, labelWidth: 100, labelAlign: 'left' ,format: 'yyyy-MM-dd',
        		onChangeDate : function(value){
        			$("#eddt").val(value);
        		}
        	});
        }
        
        function initCrLstForm(){
        	var fncInsId =$("#fncInsId").val();
        	combdata1 = $("#crId").ligerComboBox({ 
			        url:'<%=path%>/rfbase/scmbaseinfo/initCrList.do?insId='+fncInsId,
			        ajaxType :'GET', 
			        valueField: 'crId', textField: 'crNm',
					columns: [
		                { header: '授信编号', name: 'crId', width: 140 }, 
		                { header: '授信名称', name: 'crNm', width: 120 },
		                { header: '授信主体', name: 'crSbjNm', width: 120 },
		            ], 
		            width: 200,
		            selectBoxWidth: 480, selectBoxHeight: 240,
		            onChangeValue: function (newvalue){
		            	if(newvalue != null && newvalue != ""){
		            		var cridval = $("#crId").ligerGetComboBoxManager().getValue()
		            		console.log(cridval);
		            		$("#crIdVal").val(cridval);
		            		initPdList();
		            	}
		            }
                });
        }
        
        function initPdList(){
     	   var instid = $("#fncInsId").val();
   		   var cridval = $("#crId").ligerGetComboBoxManager().getValue()
     	   combdata2 = $("#pdId").ligerComboBox({
               columns: [
		            { header: '授信编号', name: 'crId', width: 140}, 
	                { header: '产品编号', name: 'pdId', width: 140}, 
	                { header: '产品名称', name: 'pdNm', width: 120},
	               ],
	            url:'<%=path%>/rfbase/scmbaseinfo/initPdList.do?insId='+instid+'&crid='+cridval,
	            ajaxType :'GET',
	            width: 200, slide: false,
	            selectBoxWidth: 480, selectBoxHeight: 240,
	            valueField: 'hid', textField: 'pdNm',
	            onChangeValue: function (newvalue){
	            	if(newvalue != null && newvalue != ""){
	            		var pdidval = $("#pdId").ligerGetComboBoxManager().getValue()
	            		console.log(pdidval);
	            		$("#pdIdVal").val(pdidval);
	            	}
	            }           
	       });
        }
        
        function switchIrtForm(){
        	var irtTpcd = $("#irtTpcd").val();
        	if(irtTpcd=="1"){
        		showIrtForm();
        	}
        	if(irtTpcd=="0"){
        		hideIrtForm();
        	}
        }
        
        function switchAbroadForm(){
        	var wthrSupAbr = $("#wthrSupAbr").val();
        	if(wthrSupAbr=="1"){
        		showAbroadForm();
        	}
        	if(wthrSupAbr=="0"){
        		hideAbroadForm();
        	}
        }
        
        function showIrtForm(){
        	$("#s2").show();
        	$("[title=prymMtd]").show();
        	$("[title=intrtMtdcd]").show();
        }
        
        function hideIrtForm(){
        	$("#s2").hide();
        	$("[title=prymMtd]").hide();
        	$("[title=intrtMtdcd]").hide();
        }
        
        function showAbroadForm(){
			$("#abdform").show();
        }
        
        function hideAbroadForm(){
			$("#abdform").hide();
        }
        
    	function formValidate(){
    		  $("#scm_bsc_info_form").validate({
    			    rules: {
    			    	fncScmNm: "required",
    			    	scmIntrt: "required",
    			    	rePyTpCd: "required"
    			    	
    				    }
    			});    		
    	}
        
        //保存事件
        function saveScmBaseBtnEvent(){
        	$("#scm_bsc_info_add_btn_id").click(function(event) {
                var form = liger.get("scm_bsc_info_form");
                var scmIntrtval = $("#scmIntrt").val();
                if (!form.valid()|| scmIntrtval=='0.0000') {
                	if(scmIntrtval=='0.0000'){
                		$("#scmIntrt").parent().addClass("l-text-invalid");
                	}
                	UIUtils.alertWarning(LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO);
                    return false; //验证不通过，不执行以下代码
                }
//              2018-06-08
                if (!form.valid()|| scmIntrtval<0.0000) {
                	alert("报价利率必须为正数！");
                	return false;
                }
                var manager = $("#cost1").ligerGetGridManager();
                var rows = manager.rows; 
                for (var i = 0; i < rows.length; i++) {
                	 //费用名称含保证金,是否保证金，为是;
               	 if(rows[i].mrgnIs=='undefined'|| rows[i].mrgnIs==null || rows[i].mrgnIs==''){
               		 if(rows[i].costNm.indexOf("保证金")!=-1){
               			 if(confirm("计费信息中第"+(i+1)+"行【费用名称】是保证金时,【是否保证金】为否！确认继续么？")==false){
               				 return false; 
               			 }
               		 }
               	 }else{
               		 if(rows[i].mrgnIs=='0'){
                   		 if(rows[i].costNm.indexOf("保证金")!=-1){
                   			 if(confirm("计费信息中第"+(i+1)+"行【费用名称】是保证金时,【是否保证金】为否！确认继续么？")==false){
                   				 return false;
                   			 }
                   		 }
                   	 } 
               	 }//end if
                    if(( rows[i].costNm != null &&  rows[i].costNm != "")&&(rows[i].costPct =='undefined' || rows[i].costPct == null || rows[i].costPct == ''|| rows[i].costPct == '0')&&(rows[i].costAmt =='undefined' || rows[i].costAmt == null || rows[i].costAmt == ''|| rows[i].costAmt == '0')){
                   	 $.ligerDialog.warn("计费信息中第"+(i+1)+"行费用金额和费用比例至少维护一项！");
                   	 return false;
                    }
                }
                var beginDate=$("#stdt").val();  
                var endDate=$("#eddt").val();  
				console.log(beginDate+"___"+endDate);
                var d1 = new Date(beginDate.replace(/\-/g, "\/"));  
                var d2 = new Date(endDate.replace(/\-/g, "\/"));  
                 if(beginDate!=""&&endDate!=""&&d1 >=d2)  
                {  
                 alert("开始时间不能大于结束时间！");  
                 return false;  
                }
                var absval = $("#abs").val();
                var cridval = $("#crId").val();
                if(absval != null && absval != "" && absval == "0" && (cridval == null || cridval == "")){
                	alert("非ABS机构必须维护授信！");
                	return false;
                }
                var intrtMtdcdVal = $("#intrtMtdcd").val();
                var bsFlotupRtoVal = $("#bsFlotupRto").val();
            	var irtTpcdVal = $("#irtTpcd").val();
				console.log(intrtMtdcdVal+"___"+bsFlotupRtoVal+"___"+irtTpcdVal);
				if(irtTpcdVal=="1"){//modify by gengchunlan 20190121
	                if(intrtMtdcdVal != null && bsFlotupRtoVal != null 
	                		&& parseFloat(bsFlotupRtoVal) >= 0 && intrtMtdcdVal != "1"){                	
	                }else{
	                	alert("当前报价存在利率浮动，请维护正确的利率上浮方式和基准利率上浮比例！！");
	                	return false;
	                }
				}
				//add 担保信息必填 校验  by gengchunlan 20191018
				var isGuarantee =$("#isGuarantee").val();
				if(null == isGuarantee || ""==isGuarantee ){
					alert("请维护 是否担保  选项！");
                	return false;
				}else{
					if('1'==isGuarantee){//是否担保为是，担保主体 /担保开始/担保到期 必填校验
						var guaranteeBody=$('#guaranteeBody').ligerComboBox().getValue();
					   console.log(guaranteeBody);
					    if(null == guaranteeBody || ""==guaranteeBody ){
					    	alert("请维护 担保主体  选项！");
		                	return false;
					    }
					    var guaranteeStart = $('#guaranteeStart').val();//担保开始日期
					    var guaranteeEnd = $('#guaranteeEnd').val();//担保到期日期
					   
					    if(null == guaranteeStart || ""==guaranteeStart){
					    	alert("请维护 担保开始日  选项！");
		                	return false;
					    }
					    if(null == guaranteeEnd || "" ==guaranteeEnd){
					    	alert("请维护 担保到期日  选项！");
		                	return false;
					    }
					    var guaS = new Date(guaranteeStart.replace(/\-/g, "\/"));  
		                var guaE = new Date(guaranteeEnd.replace(/\-/g, "\/"));  
		                
					    if(guaS>guaE){
					    	alert("担保开始日不能大于担保到期日，请核查！");
		                	return false;	
					    }
					    if('2'== guaranteeBody || '5'== guaranteeBody ){//担保主体=万钧及其他⾼ 管】or【担保主体=其他】时   担保主体备注 必填校验
					    	var guaranteeRemark =$('#guaranteeRemark').val();
					        if(null == guaranteeRemark || ""==guaranteeRemark){
					        	alert("请维护 担保主体备注  选项！");
			                	return false;
					        }
					    }
					}
				}
				//end by gengchunlan 20191018
                save();
            });
        }

    	function cancelBtn(){
  		  parent.$(".l-dialog,.l-window-mask").css("display","none"); 
		  parent.grid.reload();	
    	}
        function save()
        {   
            var data = $("form").serializeArray();
			var rmrkval = JSON.stringify($("#rmrk").val());
			var guaranteeBody=$('#guaranteeBody').ligerComboBox().getValue();
			var guaranteeBody=JSON.stringify(guaranteeBody);
            var jsondata = '{rmrk:'+rmrkval+',griddata1:'+JSON.stringify(griddata1.getData())+',formdata:'+JSON.stringify(data)+',guaranteeBody:'+guaranteeBody+'}';
            console.log(jsondata);
            $.ajax({
            	   type: "POST",
            	   url: "<%=path%>/rfbase/scmbaseinfo/saveScmBscData.do",
            	   contentType: 'application/json',
            	   data: JSON.stringify(jsondata),
            	   dataType:"json",
            	   success: function(data){
            		 if(data.nmcnt > 0){
            			 alert("报价名称已存在，请修改报价名称！");
            			 return;
            		 }
            		 if(data.result == '-1'){
            			 alert('报价添加失败！');
            		 }else{
            			 alert( "报价添加成功! 项目号:" + data.result);
            			 cancelBtn(); 
            		}
            	   }
            	});
        }
	</script>
</body>
</html>
